package com.qumitech.visualnovel.model.dao.console;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import lombok.Getter;
import lombok.Setter;


@Getter
@Setter
public class UserInfo implements Serializable {
    private Integer uid;

    private String password;

    private String salt;

    private Byte state;

    private String username;

    private Date createdAt;

    private Date updatedAt;

    private List<SysRole> sysRoleList;

    public String getCredentialsSalt(){
        return this.username+this.salt;
    }

    public JSONObject toJsonObject()
    {
        JSONObject itemData = new JSONObject();
        JSONArray rolesList = new JSONArray();
        itemData.put("uid", uid);
        itemData.put("createdAt", createdAt.getTime()/1000);
        itemData.put("updatedAt", updatedAt.getTime()/1000);
        itemData.put("username", username);
        itemData.put("state", state);
        for(SysRole sysRole: sysRoleList) {
            JSONObject roleData = new JSONObject();
            roleData.put("id", sysRole.getId());
            roleData.put("roleName", sysRole.getRoleName());
            rolesList.add(roleData);
        }
        itemData.put("roles", rolesList);
        return itemData;
    }
}